package cheme.Interpreter.AST.Arithmetic;

import cheme.Interpreter.AST.Interfaces.IAstExpression;


public class AstExponential extends AstBinaryOpAstNode
{
	public AstExponential()
	{
		super();
	}
	
	public AstExponential(IAstExpression lhs, IAstExpression rhs)
	{
		super(lhs, rhs);
	}

	public double evaluate()
	{
		assert null != getLhs();
		assert null != getRhs();
		
		double result = 0.0;
		
		if(null != getLhs() && null != getRhs())
		{
			result = Math.pow(getLhs().evaluate(), getRhs().evaluate()); 
		}
		
		return result;
	}
	
	@Override
	public String toString()
	{
		assert null != getLhs();
		assert null != getRhs();
		
		String result = "0.0";
		
		if(null != getLhs() && null != getRhs())
		{
			result = "(" + getLhs().toString() + "^" +  getRhs().toString() + ")"; 
		}
		
		return result;
	}
}
